//
//  LYAuthBaseViewController.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/8/3.
//

import UIKit

class LYAuthBaseViewController: LYBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        setupCustomBackButton()
    }
    
    private func setupCustomBackButton() {
        let backButton = UIBarButtonItem.init(image: UIImage(named: "back"),
                                              style: .plain,
                                              target: self,
                                              action: #selector(backButtonTapped))
        navigationItem.leftBarButtonItem = backButton
        navigationItem.hidesBackButton = true
    }
    
    @objc private func backButtonTapped() {
        self.view.endEditing(true)
        showDetainmentAlertView()
    }

    func showDetainmentAlertView() {
        let alert = LYCustomAlertView(
            title: "",
            message: LYlocalizedString("back_alert_title") + "\n" + LYlocalizedString("back_alert_content")
        )
        
        let giveUpBtn = LYCustomAlertViewAction.getButton(with: LYlocalizedString("Give up"),
                                                          actionType: .unObvious)
        let continueBtn = LYCustomAlertViewAction.getButton(with: LYlocalizedString("Continue"),
                                                            actionType: .obvious)
        alert.addButton(giveUpBtn) {
            alert.hide { [weak self] in
                guard let self = self else { return }
                self.navigationController?.popToViewController(ofType: LYProductDetailViewController.self, animated: true)
            }
        }
        
        alert.addButton(continueBtn) {
            alert.hide ()
        }

        // 显示弹窗
        alert.show()
    }
}
